/**
 * @(#) Source.java;
 * <p/>
 * Created on Jun 23, 2008
 * AUTHOR    ** Danil Glinenko
 * EMAIL     ** dglinenko@gmail.com
 * <p/>
 *
 * Copyright (C) 2008 Danil Glinenko. All rights reserved.
 */

package jacky.lanlan.song.test.db;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;

class Source {
	private final String name;

	private final String driver;

	private final String url;

	private final String username;

	private final String password;

	Source(final String name, final String driver, final String url, final String username, final String password) {
		if (name == null || driver == null || url == null) { throw new IllegalArgumentException(
				"Source name, driver or url cannot be null."); }
		this.name = name;
		this.driver = driver;
		this.url = url;
		this.username = username;
		this.password = password;
	}

	Connection createConnection() throws SQLException {
		final Connection jdbcCon;
		try {
			Class.forName(this.driver);
			jdbcCon = DriverManager.getConnection(this.url, this.username, this.password);
		}
		catch (ClassNotFoundException e) {
			throw new RuntimeException("Unable to load jdbc driver: " + this.driver);
		}
		return jdbcCon;
	}
	
	public String getName() {
		return this.name;
	}

	public String getDriver() {
		return this.driver;
	}

	public String getUrl() {
		return this.url;
	}

	public String getUsername() {
		return this.username;
	}

	public String getPassword() {
		return this.password;
	}
	
}
